package wfmanage.action;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.wfmanage.models.HelpDeskUser;
import edu.wfmanage.models.Ticket;

public class AddTicket extends ActionSupport {
	
	private int id;
	private String summary = "";
	private String category = "";
	private String device = "";
	private String os = "";
	private Date date;
	private String priority = "";
	private String cust_name = "";
	private String email = "";
	private String dept = "";
	private String office = "";
	private String phone = "";
	private String desc = "";
	private String comments = "";
	private int status_id;
	Map<String, Object> session = ActionContext.getContext().getSession();
	HelpDeskUser user = new HelpDeskUser();
	
	private ArrayList<HelpDeskUser> userlist = new ArrayList<HelpDeskUser>();
	
		
	public ArrayList<HelpDeskUser> getUserlist() {
		return userlist;
	}

	public void setUserlist(ArrayList<HelpDeskUser> userlist) {
		this.userlist = userlist;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getDevice() {
		return device;
	}

	public void setDevice(String device) {
		this.device = device;
	}

	public String getOs() {
		return os;
	}

	public void setOs(String os) {
		this.os = os;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	public String getCust_name() {
		return cust_name;
	}

	public void setCust_name(String cust_name) {
		this.cust_name = cust_name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	public String getOffice() {
		return office;
	}

	public void setOffice(String office) {
		this.office = office;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public int getStatus_id() {
		return status_id;
	}

	public void setStatus_id(int status_id) {
		this.status_id = status_id;
	}

	public String execute() throws Exception{
		
		if(this.cust_name.isEmpty())
			return "initial_entry";
		
		Ticket ticket = new Ticket();
		ticket.setSummary(summary);
		ticket.setCategory(category);
		ticket.setDevice(device);
		ticket.setOs(os);
		ticket.setDate(date);
		ticket.setPriority(priority);
		ticket.setCust_name(cust_name);
		ticket.setEmail(email);
		ticket.setDept(dept);
		ticket.setOffice(office);
		ticket.setPhone(phone);
		ticket.setDesc(desc);
		ticket.setComments(comments);
		ticket.setStatus_id(status_id);
		ticket.insert();
		userlist = HelpDeskUser.findUserList("HelpDesk_Admin");
		email mail=new email();
		
        for(HelpDeskUser u: userlist){
     		System.out.println("Username = " + u.getUsername());
    		System.out.println("Userid = " + u.getUserid());
    		System.out.println("Password = " + u.getPassword());
    		System.out.println("Email = " + u.getEmailid());
            mail.sendmail(u.getUsername(),u.getEmailid(),"HelpDesk_Admin",0, "NA");
             System.out.println("An email has been sent to "+u.getEmailid());
        }
		return "success";
		
	}
	
	
}
